<template>
	<view>
		<view v-if="cart.length!==0">
			<!-- 有内容展示 -->
			<!-- 地址 -->
			<my-address></my-address>
			<!-- 购物车列表 -->
			<view class="cart">
				<!-- 标题 -->
				<view class="cart-title">
					<uni-icons type="shop" size="20"></uni-icons>
					<text> 购物车 </text>
				</view>
				<!-- 列表项 -->
				<view class="cart-list">
					<uni-swipe-action>
						<block v-for="(item,index) in cart" :key="index">
							<uni-swipe-action-item :right-options="options" @click="removeGoods(item)">
								<my-goods @num-change="numchange" :showNum="true" @radio-click="goodsStateChange"
									:showRadio="true" :goods="item"></my-goods>
							</uni-swipe-action-item>
						</block>
					</uni-swipe-action>
				</view>
				<!-- 结算 -->
				<view class="my-settle">
					<my-settle @all-radio-change="allradiochange"></my-settle>
				</view>
			</view>
		</view>
		<!-- 没数据展示 -->
		<view v-else class="empty-box">
			<!-- 图片 -->
			<view class="image-box">
				<image src="../../static/images/empty.png"></image>
			</view>
			<!-- 文字 -->
			<text> 哦买噶空得！ </text>
		</view>
	</view>
</template>

<script>
	import tabBarMixins from '../../mixins/tabBarMixins.js'
	import {
		mapState,
		mapMutations
	} from 'vuex'
	export default {
		data() {
			return {
				options: [{
					text: '删除',
					style: {
						backgroundColor: '#ea4350',
						color: '#fff',

					}
				}]
			};
		},
		computed: {
			...mapState('m_cart', ['cart'])
		},
		methods: {
			...mapMutations('m_cart', ['updateGoodsState', 'updateGoodscount', 'updateRemoveGoods','updateAllChecked']),
			// 全选反选
			allradiochange(checked){
				this.updateAllChecked(checked)
			},
			// 删除商品
			removeGoods(goods) {
				// console.log(1);
				this.updateRemoveGoods(goods)
			},
			// 数量发生改变时
			numchange(goods) {
				console.log(goods);
				this.updateGoodscount(goods)
			},
			// 切换goods—state状态
			goodsStateChange(goods) {
				console.log(goods);
				this.updateGoodsState(goods)
			},
		},
		mixins: [tabBarMixins]
	}
</script>

<style lang="scss">
	.cart {
		.cart-title {
			height: 40px;
			border-bottom: 1px solid #eee;
			display: flex;
			align-items: center;
			padding-left: 6px;
			font-size: 12px;

			text {
				margin-right: 6px;

			}
		}
	}
	.my-settle{
		position: fixed;
		left: 0;
		bottom: 0;
		z-index: 999;
		right: 0;
		background-color: #fff
	}
	.empty-box{
		display: flex;
		flex-direction: column;
		align-items: center;
		padding-top: 100px;
		font-size: 12px;
		color: gray;
		.image-box{
			width: 120px;
			height: 120px;
			border-radius: 50%;
			overflow: hidden;
			margin-bottom: 10px;
			image{
				width: 120px;
				height: 120px;
			}
		}
	}
</style>
